package cn.sunjinxin.trade.domain.model;

import cn.hutool.core.bean.BeanUtil;
import cn.sunjinxin.savior.ext.container.ExtExecutor;
import cn.sunjinxin.savior.ext.container.ExtRo;
import cn.sunjinxin.trade.domain.ability.PreorderAbility;
import cn.sunjinxin.trade.domain.enums.BizType;
import cn.sunjinxin.trade.domain.enums.ProductSkuType;
import lombok.Data;
import lombok.Setter;
import lombok.experimental.FieldDefaults;

import java.util.Date;

/**
 * @author issavior
 */
@Data
@FieldDefaults(level = lombok.AccessLevel.PRIVATE)
public class ProductSku {

    Long productSkuId;

    ProductSkuType productSkuType;

    BizType productBizType;

    String contractId;

    String settlementPrice;

    String commission;

    String retailPrice;

    Date serviceStartTime;

    Date serviceEndTime;

    /**
     * 购买数量
     */
    Long quantity;

    /**
     * 库存
     */
    Long inventory;


    public ProductSku(ProductSku productSku) {
        this.productSkuId = productSku.getProductSkuId();
        this.productSkuType = productSku.getProductSkuType();
        this.productBizType = productSku.getProductBizType();
        this.contractId = productSku.getContractId();
        this.settlementPrice = productSku.getSettlementPrice();
        this.commission = productSku.getCommission();
        this.retailPrice = productSku.getRetailPrice();
        this.serviceStartTime = productSku.getServiceStartTime();
        this.serviceEndTime = productSku.getServiceEndTime();
        this.quantity = productSku.getQuantity();
        this.inventory = productSku.getInventory();
    }

    public Boolean preorder() {
        return new ExtExecutor<>(PreorderAbility.class).execFirst(ExtRo.builder()
                .bizCode(this.getProductSkuType().name())
                .scenario("inventory")
                .industry("trade")
                .business("preorder").build(), e -> e.preorder(this));
    }


    public Boolean replenishment() {
        return new ExtExecutor<>(PreorderAbility.class).execFirst(ExtRo.builder()
                .bizCode(this.getProductSkuType().name())
                .scenario("inventory")
                .industry("trade")
                .business("preorder").build(), e -> e.replenishment(this));
    }


}
